#!/bin/bash


NAME=
PASS=
DOMAIN=
QS=qshell
DEBUG=

if [ "${NAME}" == "" ] || [ "${PASS}" == "" ] || [ "${DOMAIN}" == "" ] || [ "${QS}" == "" ]; then
    echo "Please Config First"
    exit 1
fi


PREFIX=$1

if [ "${PREFIX}" == "" ]; then
    echo "PREFIX Is Empty, This Will Delete ALL Res!!!"
    echo "DELETE ALL Res Is Not Allowed!!!"
    exit 1
fi

chmod +x ${QS}

# 检测环境
${QS} -v

# 授权
${QS} account ${NAME} ${PASS}

# 查看服务器内容
${QS} buckets
${QS} domains ${DOMAIN}


# qshell listbucket domain [prefix] stdout/file.txt
# qshell delete domain key

if [ "${DEBUG}" == "" ]; then
	${QS} listbucket ${DOMAIN} ${PREFIX} stdout | awk '{print $1}' | xargs -I{} ${QS} delete ${DOMAIN} {}
else
	${QS} listbucket ${DOMAIN} ${PREFIX} stdout | awk '{print $1}' | xargs -I{} echo ${QS} delete ${DOMAIN} {}
fi